<?php

class db{

	var $dburl;
	var $dbusuario;
	var $dbsenha;
	var $dbnome;
	var $dbconectado;
	var $dbquery;
	var $dbresult;
	var $dbrow=array();
	var $dberror=false;
	
	//constructor
	function db($url, $usuario, $senha, $nome){
		$this->dburl = $url;
		$this->dbusuario = $usuario;
		$this->dbsenha = $senha;	
		$this->dbconectado = @mysql_connect($this->dburl, $this->dbusuario, $this->dbsenha);
		  
		if ($this->dbconectado){
			if($nome!=""){
				$this->dbnome = $nome;
				$dbselect = @mysql_select_db($this->dbnome);
				if(!$dbselect){
					@mysql_close($this->dbconectado);
					$this->dbconectado = $dbselect;
				}
			}
			return $this->dbconectado;
		} else {
		    $this->dberror=true;
			return false;
		}
	}//function db
	
	function close()
	{
		if($this->dbconectado)
		{
			if($this->dbresult)
			{
				@mysql_free_result($this->dbresult);
			}
			$result = @mysql_close($this->dbconectado);
			return $result;
		}
		else
		{
			return false;
		}
	}//dbclose
	
	function query($sql=""){
		unset($this->dbresult);
		if($sql != ""){
			$this->dbresult = @mysql_query($sql, $this->dbconectado);
		}
		if($this->dbresult){
			unset($this->dbrow[$this->dbresult]);
			return $this->dbresult;
		}else{
			return false;
		}
	}//dbquery
	
	function fetcharray($id = 0)
	{
		if(!$id)
		{
			$id = $this->dbresult;
		}
		if($id){
			$this->row[$id] = @mysql_fetch_array($id);
			return $this->row[$id];
		}else{
			return false;
		}
	}//dbfetcharray
	
	function fetchrow($id = 0)
	{
		if(!$id)
		{
			$id = $this->dbresult;
		}
		if($id){
			$this->row[$id] = @mysql_fetch_row($id);
			return $this->row[$id];
		}else{
			return false;
		}
	}//dbfetchrow
	
	function numrows($id = 0)
	{
		if(!$id)
		{
			$id = $this->dbresult;
		}
		if($id){
			$this->row[$id] = @mysql_num_rows($id);
			return $this->row[$id];
		}else{
			return false;
		}
	}//dbnumrows

}// class db

?>
